package com.neuedu.collection.set;

import java.util.*;

public class SetDemo2 {
    public static void main(String[] args) {

        // object类型    自定义数据类型
        Set<User>  set = new TreeSet<>();
        User  u1 = new User("zhangsan","123456");
        User  u2 = new User("zhangsan","123456789");
        set.add(u1);
        boolean   res = set.add(u2);
        System.out.println(set.size());
        System.out.println(set);
        System.out.println(res);
        System.out.println("=======================");
        Random  random = new Random();

        Set<Integer>  set2 = new HashSet();
        while(set2.size()<7){
            set2.add(random.nextInt(25)+1);
        }
        //set2.forEach(System.out::println);



        // 排序
        Object [] arr = set2.toArray();
        for(int i =0; i < arr.length-1;i++){
            for(int j=i+1;j<arr.length;j++){

                if(Integer.parseInt(arr[i].toString()) >  Integer.parseInt(arr[j].toString())){
                    arr[i] = Integer.parseInt(arr[i].toString()) ^ Integer.parseInt(arr[j].toString());
                    arr[j] = Integer.parseInt(arr[i].toString()) ^ Integer.parseInt(arr[j].toString());
                    arr[i] = Integer.parseInt(arr[i].toString()) ^ Integer.parseInt(arr[j].toString());

                }
            }
        }
        System.out.println(Arrays.toString(arr));

    }
}
